package com.example.billbillbangumi;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class BangumiAdapter extends RecyclerView.Adapter<BangumiAdapter.ViewHolder> {
    private List<Bangumi> mBangumiList;
    static class ViewHolder extends RecyclerView.ViewHolder{
        View bangumiview;
        ImageView bangumiImage;
        TextView bangumiName;
        public ViewHolder(View view){
            super(view);
            bangumiview=view;
            bangumiImage=(ImageView)view.findViewById(R.id.bangumi_image);
            bangumiName=(TextView)view.findViewById(R.id.bangumi_name);
        }
    }
    public BangumiAdapter(List<Bangumi> bangumiList){
        mBangumiList=bangumiList;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.bangumi_item,parent,false);
        ViewHolder holder=new ViewHolder(view);
        return holder;

    }


    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        final Bangumi bangumi=mBangumiList.get(position);
        holder.bangumiName.setText(bangumi.getName());
        holder.bangumiImage.setImageResource(bangumi.getImage());
        holder.bangumiview.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){
            String name=bangumi.getName();
            Intent intent=new Intent(holder.bangumiview.getContext(),Message.class);
            intent.putExtra("name",name);
            holder.bangumiview.getContext().startActivity(intent);
        }
    });
    }

    @Override
    public int getItemCount(){
        return mBangumiList.size();
    }
}
